package jsu.hx.lost.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jsu.hx.lost.Model.entity.Notifications;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

public interface NotificationsMapper extends BaseMapper<Notifications> {

    // 示例：分页查询用户的通知（关联查询用户和物品信息）
    @Select("SELECT n.*, u.username, l.item_name AS lost_item_name, f.item_name AS found_item_name " +
            "FROM notifications n " +
            "LEFT JOIN user_profiles u ON n.user_id = u.id " +
            "LEFT JOIN lost_items l ON n.related_lost_item_id = l.id " +
            "LEFT JOIN find_items f ON n.related_found_item_id = f.id " +
            "WHERE n.user_id = #{userId}")
    IPage<Notifications> selectNotificationsWithDetails(
            Page<Notifications> page,
            @Param("userId") Long userId
    );
}